//
// Created by bill3000 on 2/8/21.
//

#ifndef INTELLI_STATE_HPP
#define INTELLI_STATE_HPP

#include <map>
#include <string>
#include <utility>

#include "transition.hpp"

class State {
public:
    State(unsigned int sc, std::string n, unsigned int ena, unsigned int exa)
        :state_code(sc), state_name(std::move(n)), entry_action(ena), exit_action(exa) {};

    unsigned int get_state_code() const{return state_code;}
    std::string get_name() {return state_name;}
    unsigned int get_entry_action() const {return entry_action;}
    unsigned int get_exit_action() const {return exit_action;}
    std::map<unsigned int, Transition>& get_transitions() {return transitions;}

    Transition* get_transition(unsigned int event_code) {
        auto iter = transitions.find(event_code);
        if(iter != transitions.end()) {
            Transition *trans = &(iter->second);
            return trans;
        }
        iter = transitions.find(0xFFFFFFFF);  //any event do
        if(iter != transitions.end()) {
            Transition *trans = &(iter->second);
            return trans;
        }
        return nullptr;
    }

private:
    unsigned int state_code;  //状态编号；
    std::string state_name;    //状态名称；
    unsigned int entry_action;  //入口动作编号
    unsigned int exit_action;   //出口动作编号
    std::map<unsigned int, Transition> transitions; //状态迁移表, event code as the map key
};

#endif //INTELLI_STATE_HPP
